appModule.controller("sessionConfigManagerController", ['$rootScope', '$scope', '$ionicPopup', '$ionicSideMenuDelegate', 'sessionConfigService', function($rootScope, $scope, $ionicPopup, $ionicSideMenuDelegate, sessionConfigService) {
    $rootScope.sessionConfigs = sessionConfigService.getAll();
    $rootScope.showDelete = false;
    $rootScope.showHistory = true;

    $scope.open = function(session) {
        $scope.$emit("openTerminal", session);
        $ionicSideMenuDelegate.toggleRight();
    };
    $scope.change = function(session) {
        $scope.$emit("changeTerminal", session);
        $ionicSideMenuDelegate.toggleRight();
    };
    $scope.close = function(session) {
        $scope.$emit("closeTerminal", session);
    };

    
    $scope.delete = function(sshSessionConfig) {
        $ionicPopup.confirm({
            title: "确定删除配置" + sshSessionConfig.name + "吗?"
        }).then(function(res) {
            if(res) {
                sessionConfigService.delete(sshSessionConfig.name);
                $rootScope.sessionConfigs = sessionConfigService.getAll();
            }
        });
    };

    $scope.edit = function(sshSessionConfig) {
        $rootScope.sshSessionConfig = sshSessionConfig;
        $rootScope.sshSessionConfig.oldName = sshSessionConfig.name;
        $ionicSideMenuDelegate.toggleLeft();
    };
}]);